<?php


use App\Library\Utils\Arr;
use Phinx\Seed\AbstractSeed;
use Faker\Factory as FakerFactory;

class ImMessageSeeder extends AbstractSeed
{
    public function getDependencies(): array
    {
        return [
            'UserSeeder',
        ];
    }

    /**
     * Run Method.
     *
     * Write your database seeder using this method.
     *
     * More information on writing seeders is available here:
     * https://book.cakephp.org/phinx/0/en/seeding.html
     */
    public function run()
    {
        $faker = FakerFactory::create('zh_CN');

        $users = $this->fetchAll('SELECT * FROM kg_user');

        $rows = [];
        for ($i = 0; $i < 2000; $i++) {
            $senderId = Arr::rand($users)['id'];
            $receiverId = Arr::rand($users)['id'];
            $rows[] = [
                'chat_id' => "{$senderId}-{$receiverId}",
                'sender_id' => $senderId,
                'receiver_id' => $receiverId,
                'receiver_type' => 1,
                'content' => $faker->text(10),
                'viewed' => 1,
                'create_time' => $faker->unixTime,
                'update_time' => $faker->unixTime,
            ];
        }
        $this->table('kg_im_message')->insert($rows)->saveData();
    }
}
